﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataService.Cache.Data
{
    public static class DataBaseHelper
    {
        /// <summary>
        /// 分表标识
        /// </summary>
        /// <returns></returns>
        public static string CreateTableNameFlag()
        {
            var time = DateTime.Now.AddMonths(-1);
            string stuff = $"_{time.ToString("yyyyMM")}";
            return stuff;
        }
        /// <summary>
        /// 创建分表标识
        /// </summary>
        /// <param name="snowId">雪花Id</param>
        /// <returns></returns>
        public static string CreateTableNameFlag(long snowId)
        {

            SnowflakeCore snowflake = new SnowflakeCore();
            var rs = snowflake.TryParse(snowId, out long ms, out int workId, out int seq);
            var time = snowflake.StartTimestamp.AddMilliseconds(ms);
            string stuff = $"_{time.ToString("yyyyMM")}";
            return stuff;
        }
        /// <summary>
        /// 根据ID得到完整表名
        /// </summary>
        /// <param name="snowId">雪花Id</param>
        /// <returns></returns>
        public static string GetTableNameById<T>(long snowId)
        {
            string flag = CreateTableNameFlag(snowId);
            string fullTableName = typeof(T).Name + flag;
            return fullTableName;
        }
    }
}
